const http = require('http')
const fs = require('fs')

http
  .createServer(function(request, response) {
    if (request.url === '/') {
      const body = fs.readFileSync('./index.html', 'utf-8')
      response.writeHead(200, {
        'Content-Type': 'text/html',
        'Content-Security-Policy': `default-src 'self'; form-action 'self'`
      })
      response.end(body)
    }
    if (request.url === '/test.js') {
      const body = fs.readFileSync('./test.js', 'utf-8')
      response.writeHead(200, {
        'Content-Type': 'text/javascript'
      })
      response.end(body)
    }
  })
  .listen(8888)

console.log('server in 8888')
